import { getUserInfoApi, loginApi } from '@/api/user'
import { setToken, getToken } from '@/utils/auth'
const state = {
  token: getToken() || '',
  userInfo: {}
}
const mutations = {
  setToken(state, data) {
    setToken(data)
    state.token = data
  },
  setUserInfo(state, data) {
    state.userInfo = data
  }
}
const actions = {
  async login(store, data) {
    const res = await loginApi(data)
    console.log(11);
    console.log('vuex', res)
    store.commit('setToken', res)

    // loginApi(data).then(res => {
    //   console.log('vuex', res)
    //   store.commit('setToken', res.data.data)
    // })
  },
  async getUserInfo(store) {
    const res = await getUserInfoApi()

    store.commit('setUserInfo', res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}